# 可视化输出
# 模型的输出结果跟数据集的标签都是单通道的图像，因此直接打开的话就是一张黑黑的图像，
# 如果想要看清输出结果，可以将输出结果转换成灰度图：

# In [60]
# %matplotlib inline
import cv2
import numpy as np
import matplotlib.pyplot as plt

index = 10001
image = cv2.imread("data/data125507/data_2022_baseline/JPEGImages/0{}.jpg".format(index))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
result = cv2.imread("results/result/{}.png".format(index))
result = cv2.cvtColor(result, cv2.COLOR_BGR2GRAY)
plt.imshow(image)
plt.show()
plt.imshow(result)
plt.show()

# flask 命令
rom flask import Flask
from flask import request
from flask import render_template
import os
app = Flask(__name__, static_folder="./")
@app.route('/')
def hello_segmentation():
    return render_template('home.html')
@app.route('/upload')
def upload():
    return render_template('upload.html')
@app.route('/save', methods=['GET', 'POST'])
def save():
    try:
        if request.method == 'POST' and request.files['img']:
            f = request.files['img']
            f.save('saved_files/img.png')
            os.system('python /home/aistudio/work/PaddleSeg/predict.py --image_path saved_files \
            --model_path ./model.pdparams \
            --save_dir saved_imgs \
            --crop_size 512 512 \
            --config pspnet.yml')
            return render_template('success.html')
        else:
            return render_template('failure.html')
    except:
        return render_template('failure.html')